/*
 * @Author       : NaN 353362604@qq.com
 * @Date         : 2023-08-13 14:07:19
 * @LastEditTime : 2023-08-14 08:37:21
 * @LastEditors  : NaN 353362604@qq.com
 * @FilePath     : \AdminStration\src\Pages\Front\Assets\Template\BeamNavTop.jsx
 * @Description  :
 */
import { Select } from 'antd'
import { useMount, useRequest } from 'ahooks'
import { useEffect, useState } from 'react'
import { Http } from '../../../../Common/Api'
import './Scss/BeamNavTop.scss'

export const BeamNavTop001 = ({ top, NavEvent }) => {
    const [Active, setActive] = useState(0)

    const [Data, setData] = useState()

    const { runAsync } = useRequest(Http, {
        manual: true,
        onSuccess: res => {
            const [{ organizationUuid, remark }] = res.list
            setData(res.list)
            setActive(organizationUuid)
            NavEvent.emit({ organizationUuid, remark })
        },
    })

    useEffect(() => {
        runAsync({ url: 'getBeamModelList' })
    }, [runAsync])

    return (
        <div className="BeamNavTop001" style={{ top }}>
            {Data?.length > 1 && (
                <div>
                    {Data.map(({ organizationUuid, tableName, remark }) => (
                        <div
                            key={organizationUuid}
                            className={Active === organizationUuid ? 'active' : ''}
                            onClick={() => {
                                if (Active === organizationUuid) return false
                                setActive(organizationUuid)
                                NavEvent.emit({ organizationUuid, remark })
                            }}
                        >
                            {tableName}
                        </div>
                    ))}
                </div>
            )}
        </div>
    )
}

export const BeamNavTop002 = ({ top, NavEvent, uuid }) => {
    const [Active, setActive] = useState()
    const [options] = useState([{ label: '鹤岗至苔青B2-1工区', value: '6b5620c6-54a6-417a-b85c-2b9cb114cd42' }])

    // const { runAsync } = useRequest(Http, {
    //     manual: true,
    //     onSuccess: res => {
    //         if (res.list.length === 0) return false
    //         const data = res.list.map(item => ({ label: item.tableName, value: item.code }))
    //         console.log(data)
    //         setOptions(data)
    //         setActive(data[0].value)

    //         // const [{ organizationUuid, remark }] = res.list
    //         // setData(res.list)
    //         // setActive(organizationUuid)
    //         // NavEvent.emit({ organizationUuid, remark })
    //     },
    // })

    // useEffect(() => {
    //     runAsync({ url: 'getListBeamModelsByOrg', data: { OrganizationUuid: uuid || null } })
    // }, [runAsync, uuid])

    useEffect(() => {
        setActive('6b5620c6-54a6-417a-b85c-2b9cb114cd42')
        NavEvent.emit({
            organizationUuid: '6b5620c6-54a6-417a-b85c-2b9cb114cd42',
            remark: '{"lat":47.561574,"lng":129.257066,"alt":387.3,"heading":52.9,"pitch":-46.3}',
        })
    }, [Active, NavEvent])

    const onChange = e => setActive(e)

    return (
        <div className="BeamNavTop002" style={{ top }}>
            <Select value={Active} options={options} onChange={onChange} />
        </div>
    )
}
